package org.example.erp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.erp.domain.Material;
import org.example.erp.myInterface.NodeMapper;
import org.example.erp.service.MaterialService;
import org.example.erp.mapper.MaterialMapper;
import org.example.erp.utils.TreeBuild;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 28254
* @description 针对表【material(物料产品分类)】的数据库操作Service实现
* @createDate 2024-10-28 13:53:32
*/
@Service
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material>
    implements MaterialService{
    @Autowired
    private MaterialMapper materialMapper;
    public List<Material> findMaterial(String materialName,Integer status){
        List<Material> materialList = materialMapper.findMaterial(materialName,status);
        TreeBuild<Material> treeBuild = new TreeBuild<>();
        // 创建NodeMapper实例
        NodeMapper<Material> materialMapper = TreeBuild.createNodeMapper(
                Material::getMaterialId,
                Material::getParentId,
                Material::getChildren,
                Material::setChildren
        );
      return  treeBuild.buildTree(materialList,materialMapper);
    }
}




